/**
 * 任务系统相关API
 */
import { get, post } from './request'

// 获取任务列表
export function getQuestList(type = '') {
  return post('/adventure/main_list', {
    type // main(主线)
  })
}

// 接取任务
export function acceptQuest(questId) {
  return post('/quest/accept', {
    quest_id: questId
  })
}

// 完成任务
export function completeQuest(questId) {
  return post('/quest/complete', {
    quest_id: questId
  })
}

// 领取任务奖励
export function claimQuestReward(questId) {
  return post('/quest/claim_reward', {
    quest_id: questId
  })
}

// 获取任务进度
export function getQuestProgress(questId) {
  return get(`/quest/progress/${questId}`)
}

// 更新任务进度
export function updateQuestProgress(questId, progress, action = '') {
  return post('/quest/update_progress', {
    quest_id: questId,
    progress,
    action
  })
}

// 获取任务对话
export function getQuestDialogue(questId, step) {
  return get(`/quest/dialogue/${questId}/${step}`)
}

// 选择对话选项
export function chooseDialogueOption(questId, step, optionId) {
  return post('/quest/choose_option', {
    quest_id: questId,
    step,
    option_id: optionId
  })
}

// 刷新门派任务
export function refreshSectQuests() {
  return post('/quest/sect/refresh')
}

// 触发奇遇任务
export function triggerAdventure(locationId) {
  return post('/quest/adventure/trigger', {
    location_id: locationId
  })
}

// 选择奇遇选项
export function chooseAdventureOption(adventureId, optionId) {
  return post('/quest/adventure/choose', {
    adventure_id: adventureId,
    option_id: optionId
  })
}

// 完成伙伴任务
export function completePartnerQuest(questId) {
  return post('/quest/partner/complete', {
    quest_id: questId
  })
}

export default {
  getQuestList,
  acceptQuest,
  completeQuest,
  claimQuestReward,
  getQuestProgress,
  updateQuestProgress,
  getQuestDialogue,
  chooseDialogueOption,
  refreshSectQuests,
  triggerAdventure,
  chooseAdventureOption,
  completePartnerQuest
}